package beans.thread.hebeiguoshui;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.Socket;
import java.net.UnknownHostException;

/**
 * 河北国税例子。
 * 
 * @author Jert
 * 
 */
public class Client
{

	public static void main(String[] args)
	{
		try
		{
			Socket s = new Socket("127.0.0.1", 9098);
			InputStream is = s.getInputStream();
			OutputStream os = s.getOutputStream();

			BufferedReader brKey = new BufferedReader(new InputStreamReader(System.in));
			BufferedReader br = new BufferedReader(new InputStreamReader(is));
			BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(os));

			while (true)
			{
				String strKey = brKey.readLine();
				bw.write(strKey + System.getProperty("line.separator"));
				bw.flush();
				if (strKey.equals("goodbye"))
					break;
				String str = br.readLine();
				System.out.println(str);
			}
			brKey.close();
			br.close();
			bw.close();
			s.close();
		}
		catch (UnknownHostException e)
		{
			e.printStackTrace();
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}

	}

}
